//Set集合不会重复
{
	let list = new Set();
	list.add(5);
	list.add(7);

	console.log('size', list.size);
}

{
	let arr = [1, 2, 3, 4, 5];
	let list = new Set(arr);

	console.log('size', list.size);
}

{
	let list = new Set();
	list.add(1);
	list.add(2);
	list.add(3);

	console.log('list', list);

	let arr = [1, 2, 3, 1, 1, 2, '2', 3];
	let list2 = new Set(arr);
	console.log('unique', list2);
}

{
	let arr = ['add', 'delete', 'clear', 'has'];
	let list = new Set(arr);
	console.log('has', list.has('add'));
	console.log('delete', list.delete('add'), list);
	list.clear();
	console.log('list', list);
}

{
	let arr = ['add', 'delete', 'clear', 'has'];
	let list = new Set(arr);

	for (let key of list.keys()) {
		console.log('keys', key);
	}

	for (let key of list.values()) {
		console.log('keys', key);
	}

	for (let key of list) {
		console.log('keys', key);
	}

	for (let key of list.entries()) {
		console.log('keys', key);
	}

	list.forEach(function(item) {
		console.log(item);
	})
}

{
	//WeakSet只能是对象,对象弱引用
	let weakList = new WeakSet();
	let arg = {};
	weakList.add(arg);
	// weakList.add(2);
	console.log('weakList', weakList);
}

{
	let map = new Map();
	let arr = ['123'];

	map.set(arr, 456);

	console.log('map', map, map.get(arr));
}

{
	let map = new Map([
		['a', 123],
		['b', 456]
	]);
	console.log('map arg', map);
	console.log('size', map.size);
	console.log('delete', map.delete('a'), map);
	console.log('clear', map.clear(), map);
}

{
	let weakMap = new WeakMap();
	let o = {};
	weakMap.set(o, 123);
	console.log(weakMap.get(o));
}

{
	//数据结构横向对比，增，删，改，查
	let map = new Map();
	let array = [];
	//增
	map.set('t', 1);
	array.push({
		t: 1
	});
	console.info('map-array', map, array);
	//查
	let map_exist = map.has('t');
	let array_exist = array.find(item => item.t);
	console.info('map-array', map_exist, array_exist);
	//改
	map.set('t', 2);
	array.forEach(item => item.t ? item.t = 2 : '');
	console.info('map-array-modify', map, array);
	//删
	map.delete('t');
	let index = array.findIndex(item => item.t);
	array.splice(index, 1);
	console.info('map-array-delete', map, array);
}

{
	//set和array的对比
	let set = new Set();
	let array = [];
	//增
	set.add({
		t: 1
	});
	array.push({
		t: 1
	});
	console.log('set-array', set, array);
	//查
	let set_exist = set.has({
		t: 1
	});
	let array_exsit = array.find(item => item.t);
	console.info('set-array', set_exist, array_exsit);
	//改
	set.forEach(item => item.t ? item.t = 2 : '');
	array.forEach(item => item.t ? item.t = 2 : '');
	console.info('set-array', set, array);
	//删
	set.forEach(item => item.t ? set.delete(item) : '');
	let index = array.findIndex(item => item.t);
	array.splice(index, 1);
	console.info('set-array-empty', set, array);
}

{
	//map,set,object对比
	let item = {t:1};
	let map = new Map();
	let set = new Set();
	let obj = new Object();
}
